home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.constraints;
-
- import java.util.Vector;
-
- /**
- * This abstract class provides that base class for all "external" (aka
- * heavyweight) constraints. External constraints can provide values from
- * any source capable of supporting this protocol (which includes operations
- * attaching and detaching dependency edges, retrieving or computing a value,
- * and indicating the stored or computed value has been changed).<p>
- *
- * @author Scott Hudson
- */
- public abstract class external_constraint
- implements value_provider, value_consumer {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Local mark for breaking cycles. This is true while a mark out-of-date
- * traversal which has passed through this constraint is still going on.
- * if the traversal reaches a constraint with this value set it indicates
- * a cycle.
- */
- protected boolean _doing_ood;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** The set of things we notify when values are out-of-date. This Vector
- * contains consumer_part_ref objects. */
- protected Vector _notify_list;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Default constructor. */
- public external_constraint()
- {
- /* probably only have one thing to notify, so build a small vector */
- _notify_list = new Vector(1);
-
- /* not doing out-of-date propagation */
- _doing_ood = false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Compute an up-to-date copy of (or reference to) the value produced by this
- * constraint. Here part_number is ignored since we only provide one value.
- * This gets overridden to provide the actual computation done by this
- * constraint.<p>
- *
- * @param int part_number the internal part number for the value desired. In
- * this case only part 0 is supported, so this is
- * ignored.
- */
- public abstract Object get_value(int part_number);
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Register something as interested in (dependent on) one of the parts of
- * this object. The entity registered is a part within a value_consumer
- * object. Whenever a value represented by this value_provider changes
- * (or might change), the value_ood() method must be invoked on each
- * currently registered (object,part). Here we ignore on_part_num since
- * we only have one part.<p>
- *
- * @param int on_part_num the part of this object we are attaching
- * the dependent to (in this case ignored
- * since we only have one part).
- * @param value_consumer dep_obj the dependent object.
- * @param int dep_part the part within that object which is
- * dependent.
- */
- public void attach_dependent(
- int on_part_num,
- value_consumer dep_obj,
- int dep_part)
- {
- /* add the object part to our notify list */
- _notify_list.addElement(new consumer_part_ref(dep_obj, dep_part));
- }
-
- //had:
- //* @exception bad_value if an invalid part number is given
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Remove an (object,part) pair from the dependent (interested in) list.
- * Here we ignore on_part_num since we only have one part.<p>
- *
- * @param int on_part_num the part number of this object the
- * dependent was attached to (ignored here).
- * @param value_consumer dep_obj the previously dependent object.
- * @param int dep_part the previously dependent part of that
- * object.
- */
- public void detach_dependent(
- int on_part_num,
- value_consumer dep_obj,
- int dep_part)
- {
- /* remove the part from our notify list */
- _notify_list.removeElement(new consumer_part_ref(dep_obj, dep_part));
- }
-
- //had:
- //* @exception bad_value if an invalid part number is given
- //* @exception general
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Indicate to this constraint that a value it depends on (a part of a
- * value_provider object that it is interested in) has, or might have,
- * changed value. Here we just pass this on to others that depend on us
- * (being sure to break any cycles).<p>
- *
- * @param int for_part_here the part of this object interested in
- * the value (here this is ignored since
- * we only have one part).
- * @param value_provider prov_obj the object providing the value we are
- * interested in.
- * @param int prov_part the part of the above object we are
- * interested in.
- */
- public void value_ood(
- int for_part_here,
- value_provider prov_obj,
- int prov_part)
- {
- consumer_part_ref notify_item;
-
- /* if we are in a cycle, break it */
- if (!_doing_ood)
- {
- /* don't do this again */
- _doing_ood = true;
-
- /* pass this on to our own interest set */
- for (int i = 0; i < _notify_list.size(); i++)
- {
- /* pull out the item and notify it */
- notify_item = (consumer_part_ref)_notify_list.elementAt(i);
- notify_item.obj.value_ood(notify_item.part_num, this, 0);
- }
- }
- _doing_ood = false;
- }
-
- //had
- //* @exception bad_value
- //* @exception general
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- }
-
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-